home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / rxpop12.zip / ChkPOP.cmd next >
OS/2 REXX Batch file  |  1996-06-25  |  7KB  |  253 lines

  1. /*------------------------------------------------------------------
  2.  * chkpop.cmd :
  3.  *------------------------------------------------------------------
  4.  * 08-09-92 rnr.cmd published originally by Patrick J. Mueller
  5.  * 24-01-95 adapted as chkpop.cmd by Christoph Lechleitner
  6.  * 15-12-96 fixed for more RFC-compatibility by C. Lechleitner
  7.  *------------------------------------------------------------------*/
  8.  
  9. trace off
  10.  
  11. parse arg server user password
  12.  
  13. if (server = "") | (user='') | (password='') then
  14.    do
  15.    say " Error: Expecting a pop server name, a user and a password as parameters."
  16.    exit 1
  17.    end
  18. say ' '
  19.  
  20. /*------------------------------------------------------------------
  21.  * initialize socket function package
  22.  *------------------------------------------------------------------*/
  23. parse source os .
  24.  
  25. if (os = "OS/2") then
  26.    do
  27.    if RxFuncQuery("SockLoadFuncs") then
  28.       do
  29.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  30.       rc = SockLoadFuncs()
  31.       end
  32.    end
  33.  
  34. if (os = "AIX/6000") then
  35.    do
  36.    rc = SysAddFuncPkg("rxsock.dll")
  37.    end
  38.  
  39. /*------------------------------------------------------------------
  40.  * get address of server
  41.  *------------------------------------------------------------------*/
  42. rc = SockGetHostByName(server,"host.!")
  43. if (rc = 0) then
  44.    do
  45.    say "Error: Unable to resolve server name" server
  46.    exit
  47.    end
  48.  
  49. server = host.!addr
  50.  
  51. /*------------------------------------------------------------------
  52.  * open socket
  53.  *------------------------------------------------------------------*/
  54. sock = SockSocket("AF_INET","SOCK_STREAM","IPPROTO_TCP")
  55. if (sock = -1) then
  56.    do
  57.    say "Error opening socket:" errno
  58.    exit
  59.    end
  60.  
  61. /*------------------------------------------------------------------
  62.  * connect socket
  63.  *------------------------------------------------------------------*/
  64. server.!family = "AF_INET"
  65. server.!port   = 110
  66. server.!addr   = server
  67.  
  68. rc = SockConnect(sock,"server.!")
  69. if (rc = -1) then
  70.    Error(sock,rc,"Error connecting to popserver :" errno)
  71.  
  72.    trc = GetResponse(sock)
  73.  
  74.    trc = SendMessage(sock,'USER 'user)
  75.    trc = GetResponse(sock)
  76.    parse var line.1 status rest
  77.    if status <> '+OK' then
  78.      do
  79.        say ' Error: User' user 'unknown on' server '.'
  80.        qrc = SendMessage(sock,'QUIT')
  81.        qrc = SockSoclose(sock)
  82.        exit
  83.      end
  84.  
  85.    trc = SendMessage(sock,'PASS 'password)
  86.    trc = GetResponse(sock)
  87.    parse var line.1 status rest
  88.    if status <> '+OK' then
  89.      do
  90.        say ' Error: Password wrong for' user ' on 'server'.'
  91.        qrc = SendMessage(sock,'QUIT')
  92.        qrc = SockSoclose(sock)
  93.        exit
  94.      end
  95.    else
  96.      do 
  97.        trc = SendMessage(sock,'LIST')
  98.        trc = GetResponse(sock)
  99.        messages = 0
  100.        do 
  101.          msginfo = GetResponseLine(sock)
  102.          do while msginfo <> '.'
  103.            messages = messages + 1
  104.            msginfo = GetResponseLine(sock)
  105.          end
  106.          if messages = 0 
  107.          then say ' There is no message waiting for you.'
  108.          else
  109.            do 
  110.              say ' There are' messages 'messages waiting for you.'
  111.              trc = SendMessage(sock,'LIST')
  112.              trc = GetResponse(sock)
  113.              do 
  114.                msginfo = GetResponseLine(sock)
  115.                do while msginfo <> '.'
  116.                  parse var msginfo number size
  117.                  say ' Message' number 'has' size 'bytes.'
  118.                  msginfo = GetResponseLine(sock)
  119.                end
  120.              end /* do */
  121.        end
  122.      end /* do */
  123.  
  124.    trc = SendMessage(sock,'QUIT')
  125.    trc = GetResponse(sock)
  126.  
  127. /*------------------------------------------------------------------
  128.  * quittin' time!
  129.  *------------------------------------------------------------------*/
  130. /* rc = SendMessage(sock,"quit") */
  131. rc = SockSoclose(sock)
  132. exit
  133.  
  134.  
  135. /*------------------------------------------------------------------
  136.  * help
  137.  *------------------------------------------------------------------*/
  138. Help: procedure
  139.    say "commands:"
  140.    say
  141.    say "quit    - to quit"
  142.    say "group   - to change to a particular group"
  143.    say "article - to see an article"
  144.    say
  145.    return ""
  146.  
  147. /*------------------------------------------------------------------
  148.  * get a response from the server
  149.  *------------------------------------------------------------------*/
  150. GetResponse:     procedure expose !. line.
  151.    sock = arg(1)
  152.  
  153.    moreids = "100 215 220 221 222 223 230 231"
  154.  
  155.    line.0 = 1
  156.    line.1 = GetResponseLine(sock)
  157.  
  158.    parse var line.1 rid .
  159.  
  160.    if (wordpos(rid,moreids) = 0) then
  161.       return ""
  162.  
  163.    say ' getting further lines '
  164.  
  165.    do forever
  166.       o = line.0 + 1
  167.  
  168.       line.o = GetResponseLine(sock)
  169.  
  170.       if (line.o = ".") then
  171.          return ""
  172.  
  173.       line.0 = o
  174.    end
  175.  
  176.    return ""
  177.  
  178. /*------------------------------------------------------------------
  179.  * get a line from the server
  180.  *------------------------------------------------------------------*/
  181. GetResponseLine: procedure expose !.
  182.    sock = arg(1)
  183.  
  184.    crlf = d2c(13) || d2c(10)
  185.  
  186.    if (symbol('!.buff') = "LIT") then
  187.       !.buff = ""
  188.  
  189.    do while (pos(crlf,!.buff) = 0)
  190.       rc = SockRecv(sock,"data",8000)
  191.       !.buff = !.buff || data
  192.    end
  193.  
  194.    /* say ' got data "' data '"' */
  195.    /* say ' buff = "' !.buff '"' */
  196.  
  197.  
  198.    p = pos(crlf,!.buff)
  199.  
  200.    line = substr(!.buff,1,p-1)
  201.    !.buff = substr(!.buff,p+2)
  202.  
  203.    return line
  204.  
  205. /*------------------------------------------------------------------
  206.  * send a string to the server
  207.  *------------------------------------------------------------------*/
  208. SendMessage:     procedure expose !.
  209.    sock = arg(1)
  210.    data = arg(2) || d2c(13) || d2c(10)
  211.  
  212.    /* say 'Sending "'data'" to server.' */
  213.    len = length(data)
  214.    do while (len > 0)
  215.  
  216.       len = SockSend(sock,data);
  217.       /* say 'Returncode: ' len   */
  218.       /* say 'Errorcode:  ' errno */
  219.       /*
  220.       if (errno <> 0) then
  221.          Error(-1,rc,"Error sending data to server.")
  222.       */
  223.       if (len <= 0) then
  224.          Error(sock,100,"Server closed the connection.")
  225.       
  226.       data = substr(data,len+1)
  227.       len  = length(data)
  228.    end
  229.  
  230.    return i
  231.  
  232. /*------------------------------------------------------------------
  233.  * halting ...
  234.  *------------------------------------------------------------------*/
  235. Halting:
  236.    Error(sock,1,"error on line" sigl)
  237.  
  238. /*------------------------------------------------------------------
  239.  * exit with a message and return code
  240.  *------------------------------------------------------------------*/
  241. Error: procedure
  242.    sock = arg(1)
  243.    retc = arg(2)
  244.    msg  = arg(3)
  245.  
  246.    if (sock <> -1) then
  247.       rc = SockSoClose(sock)
  248.  
  249.    say msg
  250.  
  251.    exit retc
  252.  
  253.